package com.ityuwen.mengyagushi.search.api;

import com.ityuwen.mengyagushi.common.result.Result;
import com.ityuwen.mengyagushi.query.search.AlbumIndexQuery;
import com.ityuwen.mengyagushi.search.service.SearchService;
import com.ityuwen.mengyagushi.vo.search.AlbumInfoIndexVo;
import com.ityuwen.mengyagushi.vo.search.AlbumSearchResponseVo;
import com.ityuwen.mengyagushi.vo.search.HomePageVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    @GetMapping("channel/{category1Id}")
    public Result<List<HomePageVo>> channel(@PathVariable("category1Id")Long category1Id){
        List<HomePageVo> homePageVos = this.searchService.channel(category1Id);
        return Result.ok(homePageVos);
    }

    @PostMapping
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery indexQuery){
        AlbumSearchResponseVo responseVo = this.searchService.search(indexQuery);
        return Result.ok(responseVo);
    }

    @GetMapping("findRankingList/{category1Id}/{field}")
    public Result<List<AlbumInfoIndexVo>> findRankingList(
            @PathVariable("category1Id") Long category1Id,
            @PathVariable("field") String field
    ){
        List<AlbumInfoIndexVo> albumInfoIndexVos = this.searchService.findRankingList(category1Id, field);
        return Result.ok(albumInfoIndexVos);
    }

    @GetMapping("completeSuggest/{prefix}")
    public Result<List<String>> completeSuggest(@PathVariable("prefix")String prefix){
        List<String> suggests = this.searchService.completeSuggest(prefix);
        return Result.ok(suggests);
    }

    @PostMapping("updateRanking")
    public Result updateRanking(){
        this.searchService.updateRanking();
        return Result.ok();
    }
}

